package com.biscuit.page.basicservice.design.verify_code.publish;

import com.biscuit.page.basicservice.utils.RegexUtil;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author biscuit
 * @createTime 2024/6/25 11:09
 */
@Getter
public enum VerifyCodePublishTypeEnum {

    MOBILE(1, "手机验证码"),
    EMAIL(2, "邮箱验证码");

    private final int type;

    private final String desc;

    VerifyCodePublishTypeEnum(int type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public static VerifyCodePublishTypeEnum getEnumByType(int type) {
        return Arrays.stream(VerifyCodePublishTypeEnum.values())
                .filter(x -> x.type == type).findFirst().orElse(null);
    }

    public static VerifyCodePublishTypeEnum getEnumByAccount(String account) {
        if (RegexUtil.validateMobile(account)) {
            return MOBILE;
        }
        if (RegexUtil.validateEmail(account)) {
            return EMAIL;
        }
        return null;
    }
}
